package main

import (
	"flag"
	"fmt"
	"log"
	"os"
)

var name string

func main() {
	fmt.Println(os.Args[0])

	fmt.Println(flag.Args())

	flag.Parse()
	// 创建一个新的指令名称，指定错误处理策略的FlagSet
	goCmd := flag.NewFlagSet("go", flag.ExitOnError)
	goCmd.StringVar(&name, "name", "go编程之旅", "go帮助信息")

	phpCmd := flag.NewFlagSet("php", flag.ExitOnError)
	phpCmd.StringVar(&name, "n", "php编程之旅", "php帮助信息")

	args := flag.Args()
	switch args[0] {
	case "go":
		_ = goCmd.Parse(args[1:])
	case "php":
		_ = phpCmd.Parse(args[1:])
	}

	log.Printf("name=%s", name)
}
